package org.jrfe.gfx;

import java.awt.Color;

import org.jrfe.util.ColorUtil;

/**
 * JRFE Color Object
 * Color exists out Red Green Blue and Alpha values form 0 to 1
 * r = 1 g = 1 b = 1 is White
 * a = 1 is Totally visible and a = 0 invisible
 * @author Kalvis Freimanis
 *
 */
public class ColorRGBA {
	
	/** Predefined Color */
	public static final ColorRGBA BLACK = new ColorRGBA(Color.BLACK);
	/** Predefined Color */
	public static final ColorRGBA WHITE = new ColorRGBA(Color.WHITE);
	
	/** Predefined Color */
	public static final ColorRGBA RED = new ColorRGBA(Color.RED);
	/** Predefined Color */
	public static final ColorRGBA GREEN = new ColorRGBA(Color.GREEN);
	/** Predefined Color */
	public static final ColorRGBA BLUE = new ColorRGBA(Color.BLUE);
	
	/** Predefined Color */
	public static final ColorRGBA CYAN = new ColorRGBA(Color.CYAN);
	/** Predefined Color */
	public static final ColorRGBA DARK_GRAY = new ColorRGBA(Color.DARK_GRAY);
	/** Predefined Color */
	public static final ColorRGBA GRAY = new ColorRGBA(Color.GRAY);
	/** Predefined Color */
	public static final ColorRGBA LIGHT_GRAY = new ColorRGBA(Color.LIGHT_GRAY);
	/** Predefined Color */
	public static final ColorRGBA MAGENTA = new ColorRGBA(Color.MAGENTA);
	/** Predefined Color */
	public static final ColorRGBA ORANGE = new ColorRGBA(Color.ORANGE);
	/** Predefined Color */
	public static final ColorRGBA PINK = new ColorRGBA(Color.PINK);
	/** Predefined Color */
	public static final ColorRGBA YELLOW = new ColorRGBA(Color.YELLOW);
			
	/** Colors red value */
	public float r;
	/** Color green value */
	public float g;
	/** Colors bule value */
	public float b;
	/** Colors alpha value */
	public float a;

	/**
	 * Create Default Color (White)
	 */
	public ColorRGBA() {
		this(1.f,1.f,1.f,1.f);
	}
	
	/**
	 * Crate Color form AWT Color Object
	 * @param colorAWT AWT Color Object
	 */
	public ColorRGBA(Color colorAWT){
		this(colorAWT.getRed(),colorAWT.getGreen(), colorAWT.getBlue(),colorAWT.getAlpha(),false);
	}
	
	/**
	 * Crate Color Copying from other Color
	 * @param colorRGBA color
	 */
	public ColorRGBA(ColorRGBA colorRGBA){
		this(colorRGBA.r, colorRGBA.g, colorRGBA.b, colorRGBA.a);
	}
	
	/**
	 * Create Color form values 0 to 255
	 * @param r red value 0 to 255
	 * @param g green value 0 to 255
	 * @param b blue value 0 to 255
	 * @param a alpha value 0 to 255
	 * @param dummy this value dose not matter its only there for easy use
	 */
	public ColorRGBA(int r, int g, int b, int a ,boolean dummy) {
		this(ColorUtil.convertIToF(r), ColorUtil.convertIToF(g), ColorUtil
				.convertIToF(b), ColorUtil.convertIToF(a));
		
	}

	/**
	 * Create Color from values 0 to 1
	 * @param r red value 0 to 1
	 * @param g green value 0 to 1
	 * @param b blue value 0 to 1
	 * @param a alpha value 0 to 1
	 */
	public ColorRGBA(float r, float g, float b, float a) {
		this.r = r;
		this.g = g;
		this.b = b;
		this.a = a;
	}

	/**
	 * Set Color Values
	 * @param r red value 0 to 1
	 * @param g green value 0 to 1
	 * @param b blue value 0 to 1
	 * @param a alpha value 0 to 1
	 */
 	public void setColor(float r, float g, float b, float a) {
		this.r = r;
		this.g = g;
		this.b = b;
		this.a = a;
	}
	
 	/**
 	 * Set this color from AWT color object
 	 * @param colorAWT AWT color object
 	 */
	public void setColor(Color colorAWT){
		setColor(ColorUtil.convertIToF(colorAWT.getRed()), ColorUtil.convertIToF(colorAWT.getGreen()), ColorUtil
				.convertIToF(colorAWT.getBlue()), ColorUtil.convertIToF(colorAWT.getAlpha()));
	}
	
	/**
	 * Close this color
	 */
	@Override
	public ColorRGBA clone() {
		return new ColorRGBA(this);
	}
	
	/**
	 * Print this colors values
	 */
	@Override
	public String toString() {
		return "Red:"+r+" Green:"+g+" Blue:"+b+" Alpha:"+a;
	}
}
